<?php
/**
 * Created by PhpStorm.
 * User: 17732
 * Date: 2018/6/20
 * Time: 20:39
 */

namespace app\index\controller;


use think\Controller;

class Publicmethod
{
    /**
     * 分页
     * @param array $data  数据数组
     * @param $page  当前页码
     */
    public static function pageing($data = array(),$page){
        if(!is_array($data)) return;
        if($page < 1) return ;
        $limit = 10;                                 // 每页显示条数
        $pageSum = ceil(count($data)/$limit);  // 总页数
        $pageArr['totalpage'] = $pageSum;
        $pageArr['currentPage'] = $page;
        if($page <= $pageSum){
            $start = ($page-1)*$limit;   // 开始位置
            $pageList = array_slice($data,$start,$limit);
            $pageArr['data'] = $pageList;
            return $pageArr;
        }
    }
}